@extends('admin.layout')
@section('content')
<div class="admin-biaogelist">
    <div class="listbiaoti am-cf">
      <ul class="am-icon-flag on"> 系统设置</ul>
      <dl class="am-icon-home" style="float: right;">当前位置： 首页 > <a href="#">系统设置</a></dl>
    </div>
      <div class="am-tabs am-margin" data-am-tabs>
    <ul class="am-tabs-nav am-nav am-nav-tabs">
      <li class="am-active"><a href="#tab1">密码修改</a></li>
    </ul>
    <div class="am-tabs-bd">
      <div class="am-tab-panel am-fade am-in am-active" id="tab1">
        <form class="am-form">
          <div class="am-g am-margin-top">
            <div class="am-u-sm-4 am-u-md-2 am-text-right">
              原密码
            </div>
            <div class="am-u-sm-8 am-u-md-4">
              <input type="password" class="am-input-sm" id="password">
            </div>
            <div class="am-hide-sm-only am-u-md-6"></div>
          </div>

          <div class="am-g am-margin-top">
            <div class="am-u-sm-4 am-u-md-2 am-text-right">
              新密码
            </div>
            <div class="am-u-sm-8 am-u-md-4 am-u-end col-end">
              <input type="password" class="am-input-sm" id="newpassword">
            </div>
          </div>
          <div class="am-g am-margin-top">
            <div class="am-u-sm-4 am-u-md-2 am-text-right">
              重复新密码
            </div>
            <div class="am-u-sm-8 am-u-md-4">
              <input type="password" class="am-input-sm" id="repeatpassword">
            </div>
            <div class="am-hide-sm-only am-u-md-6"></div>
          </div>
        </form>
    </div>
  </div>
  <div class="am-margin">
    <button type="button" id="submit" class="am-btn am-btn-success am-radius ">提交保存</button>
    <button type="button" class="am-btn am-btn-primary am-radius ">放弃保存</button>
  </div>
</div>
</div>
@stop
@section('ownJs')
  <script>
    $('#submit').click(function () {
      var password = $('#password').val();
      var newpassword = $('#newpassword').val();
      var repeatpassword = $('#repeatpassword').val();

      if(password == ''){
        alert("请输入原密码");
        return false;
      }else if(newpassword == ''){
        alert("请输入新密码");
        return false;
      }else if(newpassword.length < 6){
        alert("新密码长度不得低于6位");
        return false;
      }else if(repeatpassword == ''){
        alert("请再输入一遍新密码");
        return false;
      }else if(newpassword != repeatpassword){
        alert("两次新密码输入不一致");
        return false;
      }
      var data = {};
      data.old_password = password;
      data.new_password = newpassword;
      var url = '/dashboard/password';

      $.ajax({
        type: 'post',
        url: url,
        dataType: 'json',
        data:data,
        async:false,
        success: function (result) {
          if (result.code == 0) {
            alert("密码修改成功!");
            location.href = '/dashboard/setting';
          }else if (result.code == 1) {
            alert("原密码不正确!");
            location.href = location.href;
          }else if(result.code == 2){
            alert("新密码长度不得低于6位!");
            location.href = location.href;
          }else if(result.code == -1){
            location.href = '/dashboard/login';
          }
        }
      });
    });
  </script>
@stop